package com.franklin.java.api.ui.jpanel.button;

import com.intellij.ui.JBColor;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @author Franklin
 * @since 2021/9/16 10:32
 */
public class MyButton extends JButton {

    private final Color originBg = this.getBackground();
    private final Border originBorder = this.getBorder();

    public MyButton() {
        this(null);
    }

    public MyButton(Icon icon) {
        super(icon);

        doInit();
    }

    private void doInit() {
        this.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                MyButton.this.setBorder(BorderFactory.createLineBorder(JBColor.BLUE));
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {
                MyButton.this.setBorder(originBorder);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                MyButton.this.setBackground(JBColor.DARK_GRAY);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                MyButton.this.setBackground(originBg);
                MyButton.this.setBorder(originBorder);
            }
        });
    }

}
